package com.group.yztcedu.playlive.main.home.loadmore;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.group.yztcedu.playlive.R;
import com.group.yztcedu.playlive.base.BaseActivity;
import com.group.yztcedu.playlive.bean.LoadMoreDataBean;
import com.group.yztcedu.playlive.bean.LoadMoreLivesBean;
import com.group.yztcedu.playlive.config.UrlConfig;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoadMoreActivity extends BaseActivity implements LoadMoreContract.View {
    @BindView(R.id.load_more_back_iv)
    ImageView loadMoreBackIv;
    @BindView(R.id.load_more_name)
    TextView loadMoreName;
    @BindView(R.id.home_gridView_hotRoom)
    GridView homeGridViewHotRoom;
    private List<LoadMoreLivesBean> loadMoreLivesBeanList;
    private LoadMoreContract.Model model;
    private LoadMoreContract.Presenter presenter;
    private LoadMoreAdapter adapter;
    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_load_more);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        Log.i("TAG","==================="+name);
        initView();
    }

    private void initView() {
        model = new LoadMoreModel(name);
        presenter = new LoadMorePresenter(this, model);
        presenter.initData(initParams());
        loadMoreLivesBeanList = new ArrayList<>();
        adapter = new LoadMoreAdapter(loadMoreLivesBeanList);
        homeGridViewHotRoom.setAdapter(adapter);

    }

    private HashMap<String, String> initParams() {
        HashMap<String, String> params = new HashMap<>();
        params.put(UrlConfig.Key.PAGE, "1");
        params.put(UrlConfig.Key.VERSION_CODE, "20025");
        return params;
    }


    @Override
    public void onSuccessGetLoadMore(LoadMoreDataBean loadMoreDataBean) {
        loadMoreLivesBeanList.addAll(loadMoreDataBean.getLives());
        loadMoreName.setText(loadMoreDataBean.getTag().getName());
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onFailGetLoadMore(String msg) {
        Toast.makeText(LoadMoreActivity.this, msg, Toast.LENGTH_SHORT).show();
    }

    @OnClick(R.id.load_more_back_iv)
    public void onClick() {
        finish();
    }
}
